package ai.fabu.dataplatform.help;


import ai.fabu.dataplatform.constant.ResultCode;
import lombok.Data;

@Data
public class Result<T> {

    private int code;
    private String msg;
    private T data;

    public Result() {
    }

    public Result(ResultCode resultCode, T data) {
        this(resultCode);
        this.data = data;
    }

    public Result(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }


    /**
     * 返回结果代码code和消息msg，并返回值
     * @param code 结果类型
     * @param object 返回值
     */
    public void returnWithValue(ResultCode code,T object){
        this.code = code.getCode();
        this.msg = code.getMsg();
        this.data = object;
    }

    /**
     * 返回结果代码code和消息msg，不需要返回值
     * @param code 结果类型
     */
    public void returnWithoutValue(ResultCode code){
        this.code = code.getCode();
        this.msg = code.getMsg();
    }

    public void returnWithOutValue(Result result){
        this.code = result.getCode();
        this.msg = result.getMsg();
    }


}


